#include "myprogressbar.h"
#include<QPainter>
MyProgressBar::MyProgressBar(QWidget *parent):QProgressBar(parent)
{
    setMinimum(0);
    setMaximum(100);
    setValue(0);
}
void MyProgressBar::paintEvent(QPaintEvent * ){
    QRect prgRec=QRect(0,0,width()*5/6,height());
    QRect textRec=QRect(width()*5/6,0,width()/6,height());
    const double p=(double)(value()-minimum())/(maximum()-minimum());

    int x=(int)(prgRec.width()*p);

    QRect prorect=prgRec.adjusted(0,0,x-prgRec.width(),0);

    QPainter painter(this);
    painter.drawPixmap(prgRec,QPixmap(":/new/prefix1/images/progress_back.png"));
    painter.drawPixmap(prorect,QPixmap(":/new/prefix1/images/progress_front.png"));

    QString valstr=QString("%1%").arg(value());
    QFont font("微软雅黑",10,QFont::Bold);
    painter.setFont(font);
    painter.setPen(QColor("#666666"));
    painter.drawText(textRec,Qt::AlignCenter,valstr);
}
